const {con, Result} = require('./common');

let login = async(email, password) => {
  let res = new Result();

  let sql = `select * from users where email = '${email}'`;
  let [rows] = await con.execute(sql);
  if(rows.length === 0){
    res.code = 40101;
    res.msg = 'user not exist';
  } else if(rows[0].password !== password) {
    res.code = 40102;
    res.msg = 'password error';
  } else {
    res.data = rows[0];
  }
  return res;
};

module.exports = {login}
